from PyQt5.QtWidgets import *
from PyQt5 import QtGui,QtCore
from PyQt5.QtGui import QIcon
class TrayModel(QSystemTrayIcon):
    def __init__(self, Window):
        super(TrayModel, self).__init__()
        self.window = Window
        self.init_ui()

    def init_ui(self):
        # 初始化菜单
        self.menu = QMenu()

        self.stop_action = QAction('停止录制屏幕', self, triggered=self.stop_record)
        self.stop_action.setDisabled(True)
        self.quit_action = QAction('退出', self, triggered=self.quit_recordk)
        self.about_action =QAction('关于',self,triggered=self.about)
        self.start_action =QAction('开始录制屏幕', self, triggered=self.start_record)
        self.menu.addAction(self.start_action)
        self.menu.addAction(self.stop_action)
        self.menu.addAction(self.about_action)
        self.menu.addAction(self.quit_action)

        self.setContextMenu(self.menu)

        self.setIcon(QIcon('wujiaoxing.png'))
        self.icon = self.MessageIcon()

    def start_record(self):
        self.stop_action.setDisabled(False)
        self.start_action.setDisabled(True)
        self.window.showMinimized()
    def about(self):
        pass
    def stop_record(self):
        self.start_action.setDisabled(False)
        self.stop_action.setDisabled(True)
        self.window.showNormal()
        self.window.activateWindow()

    def quit_recordk(self):
        qApp.quit()

    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        a0.ignore()
        self.hide()
        self.tray.show()
        print("closeEvent")